package Singleton;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 模仿springIOC容器的注册式单例模式
 * User:xuzhidian
 * Date:2018/3/28
 * Time:20:20
 */
public class BeanFactory {

    private BeanFactory() {

    }

    private final static Map<String, Object> ioc = new ConcurrentHashMap<>();

    public static Object getBean(String clazzName) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        ioc.putIfAbsent(clazzName, Class.forName(clazzName).newInstance());
        return ioc.get(clazzName);
    }

}
